﻿using GoodShop.Shops;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace GoodShop.Sale
{
    public class OrderInfoService : CrudAppService<OrderInfo, OrderInfoDTO, Guid, PagedAndSortedResultRequestDto, CreateUpdateOrderInfoDTO>, IOrderInfoService
    {
        IRepository<OrderInfo, Guid> _orderInforepository;
        IRepository<CommodityInfo, Guid> _shoprepository;
        IRepository<CommoditySpecifica, int> _shopbrandrepository;
        IRepository<CommodityType, int> _shoptyperepository;
        public OrderInfoService(IRepository<OrderInfo, Guid> repository,
             IRepository<OrderInfo, Guid> orderInforepository,
             IRepository<CommodityInfo, Guid> shoprepository,
             IRepository<CommoditySpecifica, int> shopbrandrepository,
             IRepository<CommodityType, int> shoptyperepository) : base(repository)
        {
            _orderInforepository = orderInforepository;
            _shoprepository = shoprepository;
            _shopbrandrepository = shopbrandrepository;
            _shoptyperepository = shoptyperepository;
        }
        [HttpGet, Route("api/Shop/OrderInfoList")]
        public async Task<PagedResultDto<OrderInfoList>> OrderInfoList()
        {
            var res = from a in await _orderInforepository.GetListAsync()
                      join b in await _shoprepository.GetListAsync() on a.ShopId equals b.CommodityId
                      join c in await _shopbrandrepository.GetListAsync() on a.ShopBrandId equals c.Id
                      join d in await _shoptyperepository.GetListAsync() on a.ShopTypeId equals d.Id
                      select new OrderInfoList
                      {
                           CommodSpeciName=c.CommodSpeciName,
                           CommodityName=b.CommodityName,
                           CommodTypeName = d.CommodTypeName,
                           ShopBrandId=c.Id,
                           ShopId=a.Id,
                           ShopTypeId=c.Id,
                           OrderInfoName=a.OrderInfoName,
                           OrderInfoAddre=a.OrderInfoAddre,
                           ShoppAddreTel=a.ShoppAddreTel,
                      

                      };
            PagedResultDto<OrderInfoList> obj = new PagedResultDto<OrderInfoList>();
            obj.Items = res.ToList();
            obj.TotalCount = (await _shoprepository.GetListAsync()).Count();
            return obj;
        }
    }
}
